import Vue from 'vue'
export default {
    //弹出成功消息
    succ: function(msg) {
        Vue.prototype.$message({
            message: msg,
            type: 'success'
        })
    },
    //弹出失败消息
    fail: function(msg) {
        Vue.prototype.$message({
            message: msg,
            type: 'error'
        })
    },
    compare: function(compareArry, editArry) {
        let flag = true
        for (let i in compareArry) {
            if (compareArry[i] !== editArry[i]) {
                flag = false
            }
        }
        if (flag) {
            this.fail('对不起，提交数据与原数据相同！')
        }
        return flag
    },
    export2Excel: function(tHeader, filterVal, list, title) {
        require.ensure([], () => {
            // const { export_json_to_excel } = require('../vendor/Export2Excel');
            const { export_json_to_excel } = require('../vendor/Export2Excel.js');
            // const tHeader = ['日期', '两种类别油的销售情况', '资金总收入', '各种卡类收入', '大客户额度结余', '油表销售总量'];
            // const filterVal = ['stringDate', 'oil1', 'oil2', 'oil3', 'oil4', 'oil5'];
            // const list = this.tableData;
            // const list = this.datas
            const data = this.formatJson(filterVal, list);
            export_json_to_excel(tHeader, data, title);
        })
    },
    formatJson: function(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]))
    },
}